package com.gdut.huayan.security;

import com.gdut.huayan.entity.dto.Result;
import com.gdut.huayan.utils.WebJsonUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, Serializable {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        Result result = new Result();
        result.setCode(401);
        result.setMessage("您没有权限访问该接口");
        WebJsonUtils.write(response, result);
    }

}